package com.yzx.lifeassistants.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.datatype.BmobFile;
import cn.bmob.v3.datatype.BmobPointer;
import cn.bmob.v3.datatype.BmobRelation;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.UpdateListener;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.wechat.favorite.WechatFavorite;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

import com.balysv.materialripple.MaterialRippleLayout;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.bean.SocializeEntity;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.controller.listener.SocializeListeners.SnsPostListener;
import com.umeng.socialize.media.UMImage;
import com.yzx.lifeassistants.GlobalParams;
import com.yzx.lifeassistants.R;
import com.yzx.lifeassistants.adapter.ShareListAdapter;
import com.yzx.lifeassistants.adapter.UnEditGridAdapter;
import com.yzx.lifeassistants.base.BaseActivity;
import com.yzx.lifeassistants.bean.ImageItem;
import com.yzx.lifeassistants.bean.LostThing;
import com.yzx.lifeassistants.bean.SharePlatform;
import com.yzx.lifeassistants.bean.User;
import com.yzx.lifeassistants.common.CommonConstant;
import com.yzx.lifeassistants.utils.AppUtils;
import com.yzx.lifeassistants.utils.FileUtils;
import com.yzx.lifeassistants.utils.LogcatUtils;
import com.yzx.lifeassistants.utils.ScreenUtils;
import com.yzx.lifeassistants.utils.ToastUtils;
import com.yzx.lifeassistants.view.widget.CircularLoadingDialog;
import com.yzx.lifeassistants.view.widget.NoScrollGridView;

/**
 * @Description: 失物找寻详情
 * @author: yzx
 * @time: 2016-4-23 上午10:23:11
 */
@SuppressLint("InflateParams")
public class LostInfoActivity extends BaseActivity implements OnClickListener,
		OnItemClickListener {

	private ImageButton backBtn;// 顶部返回按钮
	private ImageView typeIV;// 类型
	private TextView titleTV;// 标题
	private TextView phoneTV;// 号码
	private TextView typeTV;// 类别
	private TextView timeTV;// 时间
	private TextView placeTV;// 地点
	private TextView describeTV;// 描述
	private NoScrollGridView picGV;// 图片列表
	private TextView shareTV;// 分享
	private TextView loveTV;// 点赞
	private TextView callTelTV;// 联系

	private CircularLoadingDialog dialog;// 加载框
	private LostThing lostInfo;//
	private List<ImageItem> picList;// 图片列表信息
	private List<BmobFile> picFileList;// 图片文件列表
	private UnEditGridAdapter unEditAdapter;// 图片列表不可编辑的适配器
	private Drawable loveDrawable;// 已收藏
	private Drawable noLoveDrawable;// 未收藏
	private Boolean isLove;// 是否点赞过
	private Integer loveNum;// 点赞数

	// //////////QQ,QZone使用友盟分享,其余使用ShareSDK分享//////////////
	private ShareParams shareParams;// 分享内容
	private PlatformActionListener listener;// 分享回调监听
	private Bitmap bitmap;// 分享图片
	private String shareImagePath;// 分享图片路径
	private UMSocialService mShareController;// 友盟分享控制器
	private SnsPostListener snsPostListener;// 友盟分享回调监听

	private View shareView;// 分享弹框
	private AlertDialog theDialog;// 分享弹框

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lost_info);
		init();
		initView();
		setListener();
		initShareDialog();
		initMaterialRipple();
		initData();
	}

	/**
	 * 
	 * @Description: 初始化
	 */
	private void init() {
		Intent intent = getIntent();
		if (null == intent) {

		} else {
			lostInfo = (LostThing) intent.getSerializableExtra("lostInfo");
		}
	}

	/**
	 * 
	 * @Description: 初始化控件
	 */
	private void initView() {
		backBtn = (ImageButton) findViewById(R.id.lost_info_back_btn);
		typeIV = (ImageView) findViewById(R.id.lost_info_type_iv);
		titleTV = (TextView) findViewById(R.id.lost_info_title_tv);
		phoneTV = (TextView) findViewById(R.id.lost_info_tel_tv);
		typeTV = (TextView) findViewById(R.id.lost_info_type_tv);
		timeTV = (TextView) findViewById(R.id.lost_info_time_tv);
		placeTV = (TextView) findViewById(R.id.lost_info_place_tv);
		describeTV = (TextView) findViewById(R.id.lost_info_describe_tv);
		picGV = (NoScrollGridView) findViewById(R.id.lost_info_pic_gv);
		shareTV = (TextView) findViewById(R.id.lost_info_share_tv);
		loveTV = (TextView) findViewById(R.id.lost_info_love_tv);
		callTelTV = (TextView) findViewById(R.id.lost_info_call_tel_tv);
	}

	/**
	 * 
	 * @Description: 设置监听
	 */
	private void setListener() {
		backBtn.setOnClickListener(this);
		shareTV.setOnClickListener(this);
		loveTV.setOnClickListener(this);
		callTelTV.setOnClickListener(this);
		picGV.setOnItemClickListener(this);
	}

	/**
	 * 
	 * @Description: 初始化分享框
	 */
	private void initShareDialog() {
		// //////////////////////ShareSDK分享配置////////////////////////
		shareParams = new ShareParams();
		listener = new PlatformActionListener() {

			@Override
			public void onError(Platform arg0, int code, Throwable throwable) {
				LogcatUtils.e("分享失败： " + code + " " + throwable.getMessage());
				theDialog.dismiss();
				showToast("分享失败，请重试~", false);
			}

			@Override
			public void onComplete(Platform platform, int code,
					HashMap<String, Object> map) {
				theDialog.dismiss();
				showToast("分享到" + platform.getName() + "成功~", true);
			}

			@Override
			public void onCancel(Platform arg0, int code) {
				theDialog.dismiss();
				showToast("您已取消分享~", true);
			}
		};
		// //////////////////////友盟分享配置////////////////////////
		mShareController = UMServiceFactory
				.getUMSocialService("com.umeng.share");
		// 关闭自身的Toast
		mShareController.getConfig().closeToast();
		snsPostListener = new SnsPostListener() {

			@Override
			public void onStart() {
				showToast("分享中···", true);
			}

			@Override
			public void onComplete(SHARE_MEDIA media, int code,
					SocializeEntity entity) {
				switch (code) {
				case 200: {
					showToast("分享到" + media.name() + "成功~", true);
					break;
				}
				case 40000: {
					showToast("您已取消分享~", true);
					break;
				}
				default: {
					LogcatUtils.e("分享失败： " + code);
					showToast("分享失败 ，请重试~", false);
					break;
				}
				}
				theDialog.dismiss();
			}
		};
		// 弹框
		theDialog = new AlertDialog.Builder(this, R.style.ShareDialog).create();
		theDialog.setCanceledOnTouchOutside(true);
		shareView = LayoutInflater.from(this).inflate(R.layout.dialog_share,
				null);
		List<SharePlatform> shareList = new ArrayList<SharePlatform>();
		shareList.add(new SharePlatform("QQ好友",
				R.drawable.ssdk_oks_skyblue_logo_qq_checked));
		shareList.add(new SharePlatform("QQ空间",
				R.drawable.ssdk_oks_skyblue_logo_qzone_checked));
		shareList.add(new SharePlatform("新浪微博",
				R.drawable.ssdk_oks_skyblue_logo_sinaweibo_checked));
		shareList.add(new SharePlatform("微信好友",
				R.drawable.ssdk_oks_skyblue_logo_wechat_checked));
		shareList.add(new SharePlatform("微信收藏",
				R.drawable.ssdk_oks_skyblue_logo_wechatfavorite_checked));
		shareList.add(new SharePlatform("微信朋友圈",
				R.drawable.ssdk_oks_skyblue_logo_wechatmoments_checked));
		shareList.add(new SharePlatform("更多", R.drawable.ic_share_more));
		ListView shareLV = (ListView) shareView
				.findViewById(R.id.dialog_share_lv);
		ShareListAdapter adapter = new ShareListAdapter(this, shareList);
		shareLV.setAdapter(adapter);
		shareLV.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long arg3) {
				switch (position) {
				case 0: {// 分享到QQ
					shareToQQ();
					break;
				}
				case 1: {// 分享到QQ空间
					shareToQzone();
					break;
				}
				case 2: {// 分享到新浪微博
					shareToSinaWeibo();
					break;
				}
				case 3: {// 分享到微信好友
					showToast("分享中···", true);
					shareToWeChatSession();
					break;
				}
				case 4: {// 分享到微信收藏
					showToast("分享中···", true);
					shareToWeChatFavorite();
					break;
				}
				case 5: {// 分享到微信朋友圈
					showToast("分享中···", true);
					shareToWeChatTimeline();
					break;
				}
				case 6: {// 更多
					share("", null);
					break;
				}
				default:
					break;
				}
			}
		});
	}

	/**
	 * 
	 * @Description: 瓷砖特效
	 */
	private void initMaterialRipple() {
		// 动态特效
		MaterialRippleLayout
				.on(shareTV)
				.rippleColor(
						Color.parseColor(CommonConstant.RIPPLE_COLOR_LITHT))
				.rippleAlpha(CommonConstant.RIPPLE_ALPHA).rippleHover(true)
				.create();
		MaterialRippleLayout
				.on(callTelTV)
				.rippleColor(
						Color.parseColor(CommonConstant.RIPPLE_COLOR_LITHT))
				.rippleAlpha(CommonConstant.RIPPLE_ALPHA).rippleHover(true)
				.create();
		MaterialRippleLayout
				.on(loveTV)
				.rippleColor(Color.parseColor(CommonConstant.RIPPLE_COLOR_DARK))
				.rippleAlpha(CommonConstant.RIPPLE_ALPHA).rippleHover(true)
				.create();

	}

	/**
	 * 
	 * @Description: 初始化数据
	 */
	private void initData() {
		loveDrawable = getResources().getDrawable(
				R.drawable.icon_running_love_yes);
		loveDrawable.setBounds(0, 0, loveDrawable.getMinimumWidth(),
				loveDrawable.getMinimumHeight());
		noLoveDrawable = getResources().getDrawable(
				R.drawable.icon_running_love_no);
		noLoveDrawable.setBounds(0, 0, noLoveDrawable.getMinimumWidth(),
				noLoveDrawable.getMinimumHeight());
		isLove = false;
		loveNum = 0;
		dialog = new CircularLoadingDialog(this);
		picList = new ArrayList<ImageItem>();
		picFileList = new ArrayList<BmobFile>();
		if (null == lostInfo) {
			showToast("数据异常~", false);
		} else {
			titleTV.setText(lostInfo.getTitle());
			phoneTV.setText(lostInfo.getPhone());
			String type = lostInfo.getType();
			if ("U盘".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_u);
			} else if ("钱包".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_wallet);
			} else if ("书本".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_book);
			} else if ("雨伞".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_umbrella);
			} else if ("学生证".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_stu_card);
			} else if ("身份证".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_id_card);
			} else if ("银行卡".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_bank_card);
			} else if ("自行车".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_bike);
			} else if ("其他".equals(type)) {
				typeIV.setBackgroundResource(R.drawable.icon_thing_other);
			}
			typeTV.setText("类型：" + type);
			timeTV.setText("时间：" + lostInfo.getTime());
			placeTV.setText("地点：" + lostInfo.getPlace());
			describeTV.setText(lostInfo.getDescribe());
			picFileList = lostInfo.getPicFileList();
			if (null == picFileList || 1 > picFileList.size()) {

			} else {
				for (BmobFile bmobFile : picFileList) {
					if (bmobFile != null) {
						ImageItem imageItem = new ImageItem();
						imageItem.setIsLocalPic(false);
						imageItem.setFileName(bmobFile.getFilename());
						imageItem.setImagePath(bmobFile
								.getFileUrl(LostInfoActivity.this));
						picList.add(imageItem);
					}
				}
			}
			if (null == picList || 1 > picList.size()) {// 若无图片信息隐藏图片信息该栏
				picGV.setVisibility(View.GONE);
			} else {// 若有图片信息显示图片信息该栏
				picGV.setVisibility(View.VISIBLE);
				unEditAdapter = new UnEditGridAdapter(LostInfoActivity.this,
						picList);
				picGV.setAdapter(unEditAdapter);
				unEditAdapter.notifyDataSetChanged();
			}

			dialog.show();
			// 查询喜欢这个帖子的所有用户，因此查询的是用户表
			BmobQuery<User> query = new BmobQuery<User>();
			// likes是Post表中的字段，用来存储所有喜欢该帖子的用户
			query.addWhereRelatedTo("likes", new BmobPointer(lostInfo));
			query.findObjects(this, new FindListener<User>() {

				@Override
				public void onSuccess(List<User> list) {
					dialog.dismiss();
					if (null == list || 1 > list.size()) {
						loveNum = 0;
						loveTV.setText("点赞");
					} else {
						loveNum = list.size();
						loveTV.setText("点赞数:" + loveNum);
						for (User user : list) {
							if (GlobalParams.userInfo.getUsername().equals(
									user.getUsername())) {
								isLove = true;
								setLoveIcon(true);
								return;
							}
						}
					}
					isLove = false;
					setLoveIcon(false);
				}

				@Override
				public void onError(int code, String msg) {
					dialog.dismiss();
					LogcatUtils.e("获取点赞该信息的所有用户失败," + code + "：" + msg);
					loveTV.setText("点赞");
					isLove = false;
					setLoveIcon(false);
				}
			});
		}
	}

	/**
	 * 
	 * @Description: 设置显示是否收藏
	 */
	private void setLoveIcon(boolean isLove) {
		if (isLove) {
			loveTV.setCompoundDrawables(null, loveDrawable, null, null);
		} else {
			loveTV.setCompoundDrawables(null, noLoveDrawable, null, null);
		}
	}

	/**
	 * 
	 * @Description: 按键监听
	 */
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.lost_info_back_btn: {// 返回
			finish();
			break;
		}
		case R.id.lost_info_share_tv: {// 分享
			showShareDialog();
			break;
		}
		case R.id.lost_info_love_tv: {// 点赞
			loveLostInfo();
			break;
		}
		case R.id.lost_info_call_tel_tv: {// 联系
			if (null == lostInfo || null == lostInfo.getPhone()
					|| "".equals(lostInfo.getPhone())) {
				showToast("暂无联系号码~", false);
				return;
			}
			Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
					+ lostInfo.getPhone()));
			startActivity(intent);
			break;
		}
		default:
			break;
		}
	}

	/**
	 * 
	 * @Description: 点赞该信息
	 */
	private void loveLostInfo() {
		dialog.show();
		BmobRelation relation = new BmobRelation();
		if (isLove) {// 取消点赞
			relation.remove(GlobalParams.userInfo);
		} else {// 添加点赞
			relation.add(GlobalParams.userInfo);
		}
		lostInfo.setLikes(relation);
		lostInfo.update(this, new UpdateListener() {// 更新

					@Override
					public void onSuccess() {
						dialog.dismiss();
						if (isLove) {
							showToast("已取消点赞~", true);
							isLove = false;
							loveNum--;
							if (0 < loveNum) {
								loveTV.setText("点赞数:" + loveNum);
							} else {
								loveTV.setText("点赞");
							}
						} else {
							showToast("已点赞成功~", true);
							isLove = true;
							loveNum++;
							loveTV.setText("点赞数:" + loveNum);
						}
						setLoveIcon(isLove);
					}

					@Override
					public void onFailure(int code, String message) {
						dialog.dismiss();
						LogcatUtils.e("更新点赞失败," + code + "：" + message);
						if (isLove) {
							showToast("取消点赞失败~", false);
						} else {
							showToast("点赞失败~", false);
						}
					}
				});
	}

	/**
	 * 
	 * @Description: 列表监听
	 */
	@Override
	public void onItemClick(AdapterView<?> adapterView, View view,
			int position, long arg3) {
		if (position == picList.size()) {

		} else {
			String[] imagePaths = new String[picList.size()];
			for (int i = 0; i < picList.size(); i++) {
				if (picList.get(i).getIsLocalPic()) {
					imagePaths[i] = "file://" + picList.get(i).getImagePath();
				} else {
					imagePaths[i] = picList.get(i).getImagePath();
				}
			}
			loadLocalImage(position, imagePaths);
		}
	}

	/**
	 * 
	 * @Description: 加载本地的图片
	 * @param position
	 * @param imagePath
	 */
	private void loadLocalImage(int position, String[] imagePaths) {
		Intent intent = new Intent(LostInfoActivity.this,
				ImagePagerActivity.class);
		intent.putExtra(ImagePagerActivity.IMAGE_URLS, imagePaths);
		intent.putExtra(ImagePagerActivity.IMAGE_INDEX, position);
		startActivity(intent);
	}

	/**
	 * 
	 * @Description: Toast显示信息
	 */
	private void showToast(String message, Boolean isInfo) {
		if (isInfo) {
			ToastUtils.showInfoToast(this, message, R.id.lost_info_top_ll);
		} else {
			ToastUtils.showAlertToast(this, message, R.id.lost_info_top_ll);
		}

	}

	/**
	 * 
	 * @Description: 弹出推荐分享框
	 */
	@SuppressLint("NewApi")
	private void showShareDialog() {
		// 获取图片
		bitmap = ScreenUtils.snapShotWithoutStatusBar(this);
		if (null != bitmap) {
			shareImagePath = FileUtils.getImagePath();
			if (null != shareImagePath) {
				FileUtils.saveBitmap(bitmap, shareImagePath);
				if (FileUtils.isFilePathExist(shareImagePath)) {
					shareParams.setImagePath(shareImagePath);
				}
			}

		}
		theDialog.show();
		theDialog.setContentView(shareView);
		Window window = theDialog.getWindow();
		window.setGravity(Gravity.BOTTOM);
		window.getDecorView().setPadding(0, 0, 0, 0);
		WindowManager.LayoutParams lp = window.getAttributes();
		lp.width = WindowManager.LayoutParams.MATCH_PARENT;
		lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
		window.setAttributes(lp);
	}

	/**
	 * 
	 * @Description: 分享到QQ好友
	 */
	private void shareToQQ() {
		// ShareSDK图文分享 纯图片分享无法回调
		// shareParams.setText(CommonConstant.SHARE_CONTENT);
		// shareParams.setTitle(CommonConstant.SHARE_TITLE);
		// shareParams.setTitleUrl(CommonConstant.SHARE_TARGET_URL);
		// Platform qqPlatform = ShareSDK.getPlatform(QQ.NAME);
		// qqPlatform.setPlatformActionListener(listener);
		// qqPlatform.share(shareParams);
		// 使用友盟分享 QQ图文分享
		if (AppUtils.isInstallApplication("com.tencent.mobileqq")) {
			mShareController.setShareContent(null);
			if (null != bitmap) {
				mShareController.setShareImage(new UMImage(this, bitmap));
			}
			mShareController.postShare(this, SHARE_MEDIA.QQ, snsPostListener);
		} else {
			showToast("请先安装最新版QQ~", false);
		}
	}

	/**
	 * 
	 * @Description: 分享到空间
	 */
	private void shareToQzone() {
		// 使用ShareSDK分享 图片需要先上传服务器速度慢 空间不支持纯图片
		// shareParams.setTitle(CommonConstant.SHARE_TITLE);
		// shareParams.setTitleUrl(CommonConstant.SHARE_TARGET_URL);
		// shareParams.setText(CommonConstant.SHARE_CONTENT);
		// shareParams.setSite("Lifeassistants");
		// shareParams.setSiteUrl(CommonConstant.SHARE_TARGET_URL);
		// Platform qZonePlatform = ShareSDK.getPlatform(QZone.NAME);
		// // 设置false表示使用SSO授权方式
		// qZonePlatform.SSOSetting(false);
		// qZonePlatform.setPlatformActionListener(listener);
		// qZonePlatform.share(shareParams);
		// 使用友盟分享 QQ空间图文分享
		if (AppUtils.isInstallApplication("com.qzone")
				|| AppUtils.isInstallApplication("com.tencent.mobileqq")) {
			mShareController.setShareContent(CommonConstant.SHARE_CONTENT);
			if (null != bitmap) {
				mShareController.setShareImage(new UMImage(this, bitmap));
			}
			mShareController
					.postShare(this, SHARE_MEDIA.QZONE, snsPostListener);
		} else {
			showToast("请先安装最新版QQ空间或QQ~", false);
		}
	}

	/**
	 * 
	 * @Description: 分享到新浪微博
	 */
	private void shareToSinaWeibo() {
		// 新浪微博图文分享
		HashMap<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("Id", "1");// 自定义字段，整型，用于您项目中对此平台的识别符
		hashMap.put("SortId", "1");// "此平台在您分享列表中的位置，整型，数值越大越靠后"
		hashMap.put("AppKey", CommonConstant.SINA_APP_ID);// 填写您在新浪微博上注册到的AppKey
		hashMap.put("AppSecret", CommonConstant.SINA_APP_SECRET);// 填写您在新浪微博上注册到的AppSeret
		hashMap.put("RedirectUrl", CommonConstant.SINA_REDIRECT_URL);// 填写您在新浪微博上注册的RedirectUrl
		if (AppUtils.isInstallApplication("com.sina.weibo")) {
			hashMap.put("ShareByAppClient", "true");// 使用客户端进行分享
		} else {
			hashMap.put("ShareByAppClient", "false");// 不使用客户端进行分享
		}
		hashMap.put("Enable", "true");// 布尔值，标记此平台是否有效
		ShareSDK.setPlatformDevInfo(SinaWeibo.NAME, hashMap);
		if (AppUtils.isInstallApplication("com.sina.weibo")) {
			// 调用新浪微博客户端授权分享
			shareParams.setText(CommonConstant.SHARE_CONTENT);
			shareParams.setUrl(CommonConstant.SHARE_TARGET_URL);
			shareParams.setTitle(CommonConstant.SHARE_TITLE);
			shareParams.setTitleUrl(CommonConstant.SHARE_TARGET_URL);
			shareParams.setShareType(Platform.SHARE_WEBPAGE);
			Platform weibo = ShareSDK.getPlatform(SinaWeibo.NAME);
			// 设置false表示使用SSO授权方式
			weibo.SSOSetting(false);
			// 设置分享事件回调
			weibo.setPlatformActionListener(listener);
			weibo.share(shareParams);
		} else {
			// 调用网页授权分享
			OnekeyShare oks = new OnekeyShare();
			oks.setPlatform(SinaWeibo.NAME);
			// 显示编辑页面
			oks.setSilent(false);
			// 显示为Dialog
			oks.setDialogMode();
			oks.setText(CommonConstant.SHARE_CONTENT + "下载地址"
					+ CommonConstant.SHARE_TARGET_URL + " ");
			if (null != shareImagePath) {
				oks.setImagePath(shareImagePath);
			}
			oks.setCallback(listener);
			oks.show(this);
		}
	}

	/**
	 * 
	 * @Description: 分享到微信好友
	 */
	private void shareToWeChatSession() {
		if (AppUtils.isInstallApplication("com.tencent.mm")) {
			// 纯图片分享
			shareParams.setText(null);
			shareParams.setTitle(CommonConstant.SHARE_TITLE);
			// 分享类型 图片
			shareParams.setShareType(Platform.SHARE_IMAGE);
			Platform wxPlatform = ShareSDK.getPlatform(Wechat.NAME);
			wxPlatform.setPlatformActionListener(listener);
			wxPlatform.share(shareParams);
		} else {
			showToast("请先安装最新版微信~", false);
		}

	}

	/**
	 * 
	 * @Description: 分享到微信朋友圈
	 */
	private void shareToWeChatTimeline() {
		if (AppUtils.isInstallApplication("com.tencent.mm")) {
			// 纯图片分享
			shareParams.setText(null);
			shareParams.setTitle(CommonConstant.SHARE_TITLE);
			// 分享类型 图片
			shareParams.setShareType(Platform.SHARE_IMAGE);
			Platform wxTimeLinePlatform = ShareSDK
					.getPlatform(WechatMoments.NAME);
			wxTimeLinePlatform.setPlatformActionListener(listener);
			wxTimeLinePlatform.share(shareParams);
		} else {
			showToast("请先安装最新版微信~", false);
		}

	}

	/**
	 * 
	 * @Description: 分享到微信收藏
	 */
	private void shareToWeChatFavorite() {
		if (AppUtils.isInstallApplication("com.tencent.mm")) {
			// 纯图片分享
			shareParams.setText(null);
			shareParams.setTitle(CommonConstant.SHARE_TITLE);
			// 分享类型 图片
			shareParams.setShareType(Platform.SHARE_IMAGE);
			Platform wxFavoritePlatform = ShareSDK
					.getPlatform(WechatFavorite.NAME);
			wxFavoritePlatform.setPlatformActionListener(listener);
			wxFavoritePlatform.share(shareParams);
		} else {
			showToast("请先安装最新版微信~", false);
		}

	}

	/**
	 * 
	 * @Description: 分享更多
	 */
	private void share(String packages, Uri uri) {
		Intent intent = new Intent(Intent.ACTION_SEND);
		if (uri != null) {
			intent.setType("image/*");
			intent.putExtra(Intent.EXTRA_STREAM, uri);
		} else {
			intent.setType("text/plain");
		}
		intent.putExtra(Intent.EXTRA_SUBJECT, "分享到");
		intent.putExtra(Intent.EXTRA_TEXT, CommonConstant.SHARE_CONTENT
				+ "下载地址" + CommonConstant.SHARE_TARGET_URL);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		if (!TextUtils.isEmpty(packages))
			intent.setPackage(packages);
		startActivity(Intent.createChooser(intent, "分享到"));
	}
}
